using System.Collections.Generic;

public partial class ServerMessagePool
{
    static ServerMessagePool s_Instance = new ServerMessagePool();
    public static ServerMessagePool Instance=>s_Instance;

    Dictionary<System.Type, ProtobufMessagePool> msgCreator = new Dictionary<System.Type, ProtobufMessagePool>();
	public void Registe(System.Type type, ProtobufMessagePool pool)
	{
		msgCreator[type] = pool;
    }

    public T Fetch<T>() where T : class,Google.Protobuf.IMessage
	{
		return msgCreator[(typeof(T))].Get() as T;
	}

    public Google.Protobuf.IMessage Fetch(System.Type type)
	{
		return msgCreator[type].Get();
	}
	
	public void Recycle(global::Google.Protobuf.IMessage msg)
	{
		msgCreator[msg.GetType()].Put(msg);
	}
}
